<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="流程节点定义表" prop="defineNodeId">
									<el-input v-model="form.defineNodeId" placeholder="请输入流程节点定义表" clearable></el-input>
								</el-form-item>
								<el-form-item label="流程类型id" prop="defineId">
									<el-input v-model="form.defineId" placeholder="请输入流程类型id" clearable></el-input>
								</el-form-item>
								<el-form-item label="节点序号" prop="nodeIndex">
									<el-input v-model="form.nodeIndex" placeholder="请输入节点序号" clearable></el-input>
								</el-form-item>
								<el-form-item label="节点名称" prop="nodeName">
									<el-input v-model="form.nodeName" placeholder="请输入节点名称" clearable></el-input>
								</el-form-item>
								<el-form-item label="抵达本节点状态" prop="statusName">
									<el-input v-model="form.statusName" placeholder="请输入抵达本节点状态" clearable></el-input>
								</el-form-item>
								<el-form-item label="前进到该节点的按钮名称" prop="buttonToName">
									<el-input v-model="form.buttonToName" placeholder="请输入前进到该节点的按钮名称" clearable></el-input>
								</el-form-item>
								<el-form-item label="打回该节点的按钮名称" prop="buttonBackName">
									<el-input v-model="form.buttonBackName" placeholder="请输入打回该节点的按钮名称" clearable></el-input>
								</el-form-item>
								<el-form-item label="日志名称，操作人名称：如 制单人，审核人，批准人" prop="logName">
									<el-input v-model="form.logName" placeholder="请输入日志名称，操作人名称：如 制单人，审核人，批准人" clearable></el-input>
								</el-form-item>
								<el-form-item label="执行人 1角色 2部门 3个人 4多人-多条数据" prop="exeType">
									<el-input v-model="form.exeType" placeholder="请输入执行人 1角色 2部门 3个人 4多人-多条数据" clearable></el-input>
								</el-form-item>
								<el-form-item label="1并且 2或" prop="exeAndOr">
									<el-input v-model="form.exeAndOr" placeholder="请输入1并且 2或" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	import workflowAPI from '@/api/workflow/defineNode';
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: '工作流节点定义'
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					defineNodeId: "",
					defineId: "",
					nodeIndex: "",
					nodeName: "",
					statusName: "",
					buttonToName: "",
					buttonBackName: "",
					logName: "",
					exeType: "",
					exeAndOr: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await workflowAPI.defineNode.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.defineNodeId = data.defineNodeId;
				this.form.defineId = data.defineId;
				this.form.nodeIndex = data.nodeIndex;
				this.form.nodeName = data.nodeName;
				this.form.statusName = data.statusName;
				this.form.buttonToName = data.buttonToName;
				this.form.buttonBackName = data.buttonBackName;
				this.form.logName = data.logName;
				this.form.exeType = data.exeType;
				this.form.exeAndOr = data.exeAndOr;
			}
		}
	}
</script>
<style>
</style>
